/******************************************************************************
Author: Akshay Dixit
Date created: March 20, 2019
Date last modified: June 11, 2020
File Name: 7_tz.do
Project: T4D Tanzania 
Purpose: Analysis of community awareness of potential health activities
******************************************************************************/

clear all
set more off

u "$data/T4D_end_hh_clean.dta", clear

gl strata = "strata1 strata2 strata3 strata4 strata5 strata6 strata7"

* TD01 - Did […] occur in the village in the past 3 years?

desc td*
local td td1_a td2_a td3_a td4_a td5_a td6_a td7_a td8_a td9_a td10_a td11_a td12_a td13_a td14_a td15_a
foreach var of local td {
	di "`var'"
	replace `var' = 0 if `var' == 2 
	replace `var' = . if `var' == .d | `var' == .n | `var' == .r	//Don't Know coded as missing
	tab treatment, sum(`var')
	reg `var' treatment $strata, vce(cluster facility_id)
}

egen td_total = rowtotal(td1_a td2_a td3_a td4_a td5_a td6_a td7_a td8_a td9_a td10_a td11_a td12_a td13_a td14_a td15_a), missing 
tab treatment, sum(td_total)
reg td_total treatment $strata, vce(cluster facility_id)

********************************************************************************

* RESULTS - TABLE

***Label variables***
lab var td1_a "Socialization campaign aimed at encouraging women to visit health facility"
lab var td2_a "Creation of a new bylaw relating to mother and baby health"
lab var td3_a "Attempts to improve the stock of drugs/equipments at the health facility"
lab var td4_a "Attempts to improve the attitude or performance of health facility staff"
lab var td5_a "New complaint or suggestion box at the health facility"
lab var td6_a "Community members building or requesting a new health facility"
lab var td7_a "Attempts to improve health facility infrastructure"
lab var td8_a "Improvement to the road leading to the health facility"
lab var td9_a "New mobile clinic or other outreach services from the health facility"
lab var td10_a "Creation of a community savings group"
lab var td11_a "Construction of a placenta pit"
lab var td12_a "Registry of men who do not support their wives in accessing health services"
lab var td13_a "Creation of a maternity home for women to wait near the health facility"
lab var td14_a "Campaigns aimed at educating TBAs"
lab var td15_a "Additional staff allocated to the dispensary or health center"
lab var td_total "Total number of potential health activities"

	
***Produce Excel output***

//Create the table shell
putexcel set "$analysis/awareness of potential health activities.xlsx", replace

putexcel A1=("Outcome") B1=("Treatment Mean") C1=("Control Mean") D1=("Impact") ///
E1=("p-value") F1=("Effect Size") G1=("Sample Size") A19=("Number of Respondents") ///
A20=("Number of villages") B19=(2971) C19=(3037) B20=(100) C20=(100) ///
A22=("Treatment means are regression adjusted") A23=("*** p<0.01, ** p<0.05, * p<0.1") ///
A24=("Outcomes pertain to knowledge of potential health activities")

//Export variable label, regression coefficient, control mean, treatment mean, p-value, sample size
//Effect sizes are exported separately (see below)
local outcomes td_total td1_a td2_a td3_a td4_a td5_a td6_a td7_a td8_a td9_a td10_a td11_a td12_a td13_a td14_a td15_a
local row = 2
foreach var of local outcomes {
	sleep 2000
	local varlabel : var label `var'
	
	qui reg `var' treatment $strata, vce(cluster facility_id)
	
	local p = 2*ttail(e(df_r), abs(_b[treatment]/_se[treatment]))
	local stars
		if `p' < 0.10 local stars = "*" 
		if `p' < 0.05 local stars = "**" 
		if `p' < 0.01 local stars = "***"
	local impact = _b[treatment]
	
	qui sum `var' if treatment == 0
	putexcel A`row' = ("`varlabel'")
	putexcel B`row' = ((_b[treatment]) + (r(mean)))
	putexcel C`row' = (r(mean))
	putexcel D`row' = ("`impact'" + "`stars'")
	putexcel E`row' = (`p')
	putexcel F`row' = (_b[treatment]/r(sd))
	putexcel G`row' = (e(N))
	local ++row
}

********************************************************************************

clear


